DepartmentForm = Ext.extend(Ext.Window, {
	formPanel : null,
	constructor : function(a) {
		Ext.applyIf(this, a);
		this.initUIComponents();
		DepartmentForm.superclass.constructor.call(this, {
			id : "DepartmentFormWin",
			title : "部门信息",
			iconCls : "menu-department",
			layout : "fit",
			width : 400,
			height : 230,
			minWidth : 399,
			minHeight : 169,
			items : this.formPanel,
			border : false,
			modal : true,
			plain : true,
			keys : {
				key : Ext.EventObject.ENTER,
				fn : this.save,
				scope : this
			},
			buttonAlign : "center",
			buttons : [ {
				text : "保存",
				iconCls : "btn-save",
				handler : this.save,
				scope : this
			}, {
				text : "取消",
				iconCls : "btn-cancel",
				handler : function() {
					Ext.getCmp("DepartmentFormWin").close();
				}
			} ]
		});
	},
	initUIComponents : function() {
		this.formPanel = new Ext.form.FormPanel({
			frame : false,
			id : "departmentForm",
			bodyStyle : "padding : 5px;",
			layout : "form",
			defaultType : "textfield",
			url : __ctxPath + "/system/saveDepartment.do",
			defaultType : "textfield",
			reader : new Ext.data.JsonReader({
				root : "data"
			}, [ {
				name : "depId",
				mapping : "depId"
			}, {
				name : "depName",
				mapping : "depName"
			}, {
				name : "depDesc",
				mapping : "depDesc"
			},/* {
				name : "isOutUnit",
				mapping : "isOutUnit"
			},
			{
				name : "outsourcingCompany",
				mapping : "outsourcingCompany"
			},*/
			{
				name : "parentId",
				mapping : "parentId"
			} ]),
			defaults : {
				anchor : "95%,95%",
				allowBlank : false,
				selectOnFocus : true,
				msgTarget : "side"
			},
			items : [ {
				xtype : "hidden",
				name : "department.depId",
				id : "depId",
			}, {
				xtype : "hidden",
				name : "department.parentId",
				id : "parentId",
				value : this.nodeId
			}, {
				xtype : "hidden",
				name : "department.path",
				id : "path"
			}, {
				fieldLabel : "部门名",
				name : "department.depName",
//				regex: /^[\da-zA-Z\u4E00-\u9FA5]{1,12}$/,  
//                regexText:'不能输入特殊符号，最大长度12位！',   
				blankText : "部门名为必填!",
				id : "depName"
			}, {
				fieldLabel : "部门描述",
				xtype : "textarea",
				name : "department.depDesc",
				blankText : "部门描述为必填!",
				id : "depDesc"
			}/*,{
				fieldLabel : "单位",
				hiddenName : "department.isOutUnit",				
				id : "isOutUnit",
				xtype : "combo",
				mode : "local",
				editable : true,
				triggerAction : "all",
				store : [ [ "1", "本单位" ], [ "2", "外协单位" ] ],
				value : 1
			},{
				fieldLabel : "外协公司",
				hiddenName : "department.outsourcingCompany.oCompanyId",
				id : "outsourcingCompany",
				name : "department.outsourcingCompany.oCompanyName",
				xtype : "combo",
				mode : "local",
				editable : false,
				allowBlank : true,
				lazyInit : false,
				forceSelection : false,
				triggerAction : "all",
				valueField : "oCompanyId",
				displayField : "oCompanyName",
				store : new Ext.data.JsonStore(
						{
							url : __ctxPath + "/promanage/listOutSourcingCompany.do",
							autoLoad : true,
							autoShow : true,
							root : "result",
							idProperty : "oCompanyId",
							fields : [
									"oCompanyId",
									"oCompanyName" ],
						}),
				listeners : {
					expand : function() {
						if(Ext.getCmp("isOutUnit").getValue()==1){
							Ext.getCmp("outsourcingCompany").collapse();
							Ext.getCmp("outsourcingCompany").disable();
						}else{
							var comboTools = Ext.getCmp("outsourcingCompany");
							comboTools.collapse();
							new DepartmentOcCombo({comboTools : comboTools}).show();
						}
					}
				}		
				
			}*/ ]
		});
		
//		Ext.getCmp("isOutUnit").addListener("select",function(){
//			if(Ext.getCmp("isOutUnit").getValue()==2){
//				Ext.getCmp("outsourcingCompany").enable();
//			}else if(Ext.getCmp("isOutUnit").getValue()==1){
//				Ext.getCmp("outsourcingCompany").disable();
//				Ext.getCmp("outsourcingCompany").reset();
//			}
//			
//		});
		
	},
	save : function() {
		var a = Ext.getCmp("departmentTreePanel");
		if (Ext.getCmp("departmentForm").getForm().isValid()) {
			Ext.getCmp("departmentForm").getForm().submit({
				waitMsg : "正在提交部门信息",
				success : function(b, c) {
					Ext.ux.Toast.msg("操作提示", "数据操作成功！");
					if (a != null) {
						a.root.reload();
					}
					Ext.getCmp("DepartmentFormWin").close();
				}
			});
		}
	}
});